﻿/*!
* jQuery tree plugin: 
* 
* version 0.1 2011-03-10
* Requires jQuery v1.4.2 or later
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Authors: Kim Seoung Min
* Company : Kongyoung DB
*/

(function ($) {
    $.fn.Supertree = function (method) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.tooltip');
        }
    };

    var methods = {
        init: function () {
            var el = $(this);

            $("<div class='treeSelect'></div>").prependTo($(".Supertree li:has(>ul)", el));

            $(".Supertree li .treeSelect", el).click(function (e) {

//                $(this).parent().children('ul').toggle(
//                   function (e) {
//                        var _cls = $(this).is(":visible") ? "treeSelectCollapsable" : "treeSelectExpandable";
//                        $(this).parent().removeClass("treeSelectCollapsable");
//                        $(this).parent().removeClass("treeSelectExpandable");
//                        $(this).parent().addClass(_cls);
//                    });
//                e.stopPropagation();

                $(this).parent().children('ul').toggle(
                    function (e) {
                        var _cls = $(this).is(":visible") ? "treeSelectExpandable" : "treeSelectCollapsable";
                    $(this).parent().find(".treeSelect:eq(0)").removeClass("treeSelectCollapsable");
                    $(this).parent().find(".treeSelect:eq(0)").removeClass("treeSelectExpandable");
                    $(this).parent().find(".treeSelect:eq(0)").addClass(_cls);
                
                    //alert(_cls)  
                    }
                );
                e.stopPropagation();
            });

            $(".Supertree li:has(>ul)", el).find(".treeSelect:eq(0)").addClass("treeSelectExpandable");
            $(".Supertree li", el).addClass("treeSelectli");

            $("ul", el).each(function () {
                $("li:last-child", this).removeClass("treeSelectli");
                $("li:last-child", this).addClass("treeSelectliLast");
            });

           

        },

        CollapseAll: function () {
            var el = $(this);
            $(".Supertree  ul", el).hide().parent().find(".treeSelect").removeClass("treeSelectExpandable").removeClass("treeSelectCollapsable").addClass("treeSelectCollapsable");
        },

        ExpandAll: function () {
            var el = $(this);
            $(".Supertree  ul", el).show().parent().find(".treeSelect").removeClass("treeSelectExpandable").removeClass("treeSelectCollapsable").addClass("treeSelectExpandable");
        }
    }



})(jQuery);

